package com.leizi.igym.enums;

import lombok.Getter;

import java.util.Arrays;

/**
 * @Author: leizi0110
 * @CreateTime: 2024-03-30  19:59
 * @Description:
 */

@Getter
public enum ReturnCodeEnum {
    /**
     * 操作失败
     **/
    RC999(999, "操作XXX失败"),
    /**
     * 操作成功
     **/
    RC20000(20000, "success"),
    /**
     * 服务降级
     **/
    RC201(201, "服务开启降级保护,请稍后再试!"),
    /**
     * 热点参数限流
     **/
    RC202(202, "点参数限流,请稍后再试!"),
    /**
     * 系统规则不满足
     **/
    RC203(203, "系统规则不满足要求,请稍后再试!"),
    /**
     * 授权规则不通过
     **/
    RC204(204, "授权规则不通过,请稍后再试!"),
    /**
     * access_denied
     **/
    RC403(403, "无访问权限,请联系管理员授予权限"),
    /**
     * access_denied
     **/
    RC401(401, "匿名用户访问无权限资源时的异常"),
    RC404(404, "404页面找不到的异常"),
    /**
     * 服务异常
     **/
    RC500(500, "系统异常，请稍后重试"),
    RC375(375, "数学运算异常，请稍后重试"),

    INVALID_TOKEN(2001, "访问令牌不合法"),
    ACCESS_DENIED(2003, "没有权限访问该资源"),
    CLIENT_AUTHENTICATION_FAILED(1001, "客户端认证失败"),
    USERNAME_OR_PASSWORD_ERROR(1002, "用户名或密码错误"),
    ACCOUNT_STATUS_ERROR(1003, "用户名或密码错误"),
    BUSINESS_ERROR(1004, "业务逻辑异常"),
    UNSUPPORTED_GRANT_TYPE(1003, "不支持的认证模式"),
    TOKEN_ERROR(10003, "token不合法"),
    PARAMS_ERROR(40000, "请求参数错误"),
    IDENTIFY_ERROR(40001, "认证异常！"),
    STATUS_ERROR(40002, "修改状态异常！"),
    EMP_EXIST_ERROR(40003, "账号对应员工信息已存在！"),
    UPDATE_ERROR(40004, "修改异常！"),
    DELETE_ERROR(40005, "删除异常！"),
    SAVE_ERROR(40006, "保存异常！"),
    WXLOGIN_ERROR(40007, "微信登录异常！"),
    LOGIN_STATUS_ERROR(40007, "登录态异常！"),

    NOT_LOGIN_ERROR(40100, "未登录"),
    NO_AUTH_ERROR(40101, "无权限"),
    NO_IDENTIFY_ERROR(40102, "未认证"),
    NOT_FOUND_ERROR(40400, "请求数据不存在"),
    FORBIDDEN_ERROR(40300, "禁止访问"),
    SYSTEM_ERROR(50000, "系统内部异常"),
    OPERATION_ERROR(50001, "操作失败"),
    FILE_OVER_SIZE(70002,"文件过大");

    /**
     * 自定义状态码
     **/
    private final int code;
    /**
     * 自定义描述
     **/
    private final String message;

    ReturnCodeEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }

    // 遍历枚举V1
    public static ReturnCodeEnum getReturnCodeEnum(int code) {
        for (ReturnCodeEnum element : ReturnCodeEnum.values()) {
            if (element.getCode() == code) {
                return element;
            }
        }
        return null;
    }

    // 遍历枚举V2
    public static ReturnCodeEnum getReturnCodeEnumV2(int code) {
        return Arrays.stream(ReturnCodeEnum.values()).filter(x -> x.getCode() == code).findFirst().orElse(null);
    }
}
